package cz.cvut.liy.adapter;

import cz.cvut.liy.data.Statistic;
import cz.cvut.liy.data.Test;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.TextView;


public class StatisticAdapter extends BaseAdapter{

	Context context;
	
	public StatisticAdapter(Context context) {
		this.context = context;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return 3;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		Statistic statistic = new Statistic();
		Test test = Test.getStartTest();
		switch (position){
		case 0: return "Answers count: "+statistic.getTotalCountOfTestAnswers(test);
		case 1: return "Good answers count: "+statistic.getTotalCountOfGoodTestAnswers(test);
		default : return "Percentage: "+statistic.getPercentageOfTest(test)+"%";
		}
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public TextView getGenericView() {
        // Layout parameters for the ExpandableListView
        AbsListView.LayoutParams lp = new AbsListView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, 50);
         
        TextView textView = new TextView(context);
        textView.setLayoutParams(lp);
        // Center the text vertically
        textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
        // Set the text starting position
        textView.setPadding(36, 0, 0, 0);
        return textView;
    }
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		TextView tv = getGenericView();
		String text = (String) getItem(position);
		
		tv.setText(text);
		return tv;
	}

}
